# @Time: 2024/1/3 16:52
# @Autor: XS
# @File: timer.py
# @Software: PyCharm

"""
/**
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 *  O\ = /O
 * ___/`---'\____
 * .   ' \\| |// `.
 * / \\||| : |||// \
 * / _||||| -:- |||||- \
 * | | \\\ - /// | |
 * | \_| ''\---/'' | |
 * \ .-\__ `-` ___/-. /
 * ___`. .' /--.--\ `. . __
 * ."" '< `.___\_<|>_/___.' >'"".
 * | | : `- \`.;`\ _ /`;.`/ - ` : | |
 * \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---=' bug泛滥 佛已瘫痪
"""
from mmcv.utils.timer import Timer as MmcvTimer, TimerError, time


class Timer(MmcvTimer):
    def __init__(self, start=True, print_tmpl='耗时：{:.3f}秒'):
        super().__init__(start, print_tmpl)

    def since_start(self, print_tmpl='总共耗时：{:.3f}秒'):
        if not self._is_running:
            raise TimerError('timer is not running')
        self._t_last = time()
        return print_tmpl.format(self._t_last - self._t_start)

    def since_last_check(self, print_tmpl='耗时：{:.3f}秒'):
        if not self._is_running:
            raise TimerError('timer is not running')
        dur = time() - self._t_last
        self._t_last = time()
        return print_tmpl.format(dur)
